using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;

namespace ebc.patterns.tests
{
    [TestFixture]
    public class test_ExceptionHandler
    {
        [Test]
        public void pass_on_message()
        {
            var sut = new ExceptionHandler<int>(ex => {});

            int result = 0;
            sut.Out_MessageToProcess += n => result = n;
            sut.In_CatchExceptions(42);

            Assert.AreEqual(42, result);
        }


        [Test]
        public void handle_exception()
        {
            Exception exceptionCaught = null;
            var sut = new ExceptionHandler<int>(ex => exceptionCaught = ex);

            sut.Out_MessageToProcess += n => { throw new InvalidOperationException("argh!"); };
            sut.In_CatchExceptions(42);

            Assert.IsInstanceOf(typeof(InvalidOperationException), exceptionCaught);
            Assert.AreEqual("argh!", exceptionCaught.Message);
        }
    }
}